package com.king.run.activity.mine.adapter;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.king.run.R;
import com.king.run.util.PicassoUtil;

import java.util.List;

/**
 * 作者：shuizi_wade on 2017/8/22 17:05
 * 邮箱：674618016@qq.com
 */
public class EditInfoPicAdapter extends BaseAdapter {
    private Context context;
    private List<Integer> list;

    public EditInfoPicAdapter(Context context, List<Integer> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.activity_edit_info_pic_list_row, null);
            holder = new ViewHolder();
            holder.iv_pic = (ImageView) view.findViewById(R.id.iv_pic);
            view.setTag(holder);
        } else holder = (ViewHolder) view.getTag();
        // 通过WindowManager获取
        DisplayMetrics dm = new DisplayMetrics();
        ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
        ViewGroup.LayoutParams layoutParams = holder.iv_pic.getLayoutParams();
        layoutParams.height = (dm.widthPixels - 10) / 4;
        holder.iv_pic.setLayoutParams(layoutParams);
        PicassoUtil.displayDrawable(holder.iv_pic, list.get(i));
        return view;
    }

    class ViewHolder {
        ImageView iv_pic;
    }
}
